<?php

/*
 * Author: Mario Jose
 * email:  mariognu-free@yahoo.com.br
 *
 * created: October, 12nd 2007
 * modified: July, 25th 2009
*/

/*
  This script is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  This script is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

/*
 * Set same vars to use in script and manager path from links, images and others script.
 * $hostName get url from server. 
 * $urlFull make url with http and script name. 
 * $folderPath, the string have path from url without char '/' the make count number folder right.
 *     Last, chars / was removed to count number of folders and manke array with folders name.
 * $root have path from url without main path and last and first char '/'.
 *
 * @global string $pathToRoot Code return "../" to root url
 * @global array $folders Folders name from url
 * @global string $root Set path that root from url. When count folders stop here
*/


/* First and last chars from $root can't be "/" */
$root = "layouts";

$hostName = $_SERVER['SERVER_NAME'];
$urlFull = "http://" . $hostName . $_SERVER['PHP_SELF'];
$folderPath = "";
$pathToRoot = "";
$folders = array();

if (dirname($_SERVER['PHP_SELF']) !== "")
	{
	// remove first char that is /
	$folderPath = substr(dirname($_SERVER['PHP_SELF']), 1, strlen(dirname($_SERVER['PHP_SELF'])));
	// remove root path
	$folderPath = str_replace ($root, "", $folderPath);
	if ($folderPath !== "") 
		{
		// remove first char that is /
		$folderPath = substr($folderPath, 1, strlen($folderPath));
		// make array with folders
		$folders = str_replace("/", "", explode("/", $folderPath));
		}
	else
		{
		$folders = NULL;
		}
	}
else
	{
	$folderPath = "";
	$folders = NULL;
	}

if (!is_null($folders))
	{
	for($i = 0; $i < count($folders); $i++)
		{
		$pathToRoot .= "../";
		}
	}
else
	{
	$pathToRoot = "";
	}

# Include from pages
@include_once($pathToRoot . 'include/functions.php');
@include_once($pathToRoot . 'include/language.php');

?>